package com.cooksys.film_rental.bo.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cooksys.film_rental.bo.PaymentBo;
import com.cooksys.film_rental.dao.PaymentDao;
import com.cooksys.film_rental.model.Customer;
import com.cooksys.film_rental.model.Payment;
import com.cooksys.film_rental.model.Rental;
import com.cooksys.film_rental.model.Staff;

@Service("PaymentBo")
public class PaymentBoImpl implements PaymentBo {

	@Autowired(required = true)
	PaymentDao paymentDao;

	@Override
	public Payment getPaymentByPaymentId(Short paymentId) {
		return this.paymentDao.getPaymentByPaymentId(paymentId);
	}

	@Override
	public Payment getPaymentByPaymentId(String paymentId) {
		try {

			Short paymentIdAsShort = Short.valueOf(paymentId);
			return this.getPaymentByPaymentId(paymentIdAsShort);

		} catch (NumberFormatException e) {

			System.err
					.println("Could not parse Short value for paymentId from string: "
							+ paymentId);
			e.printStackTrace();
			System.err.println("Returning null value...");
			return null;

		}
	}

	@Override
	public List<Payment> searchPaymentsByStaff(Staff staff) {
		return this.paymentDao.searchPaymentsByStaff(staff);
	}

	@Override
	public List<Payment> searchPaymentsByCustomer(Customer customer) {
		return this.paymentDao.searchPaymentsByCustomer(customer);
	}

	@Override
	public List<Payment> searchPaymentsByRental(Rental rental) {
		return this.paymentDao.searchPaymentsByRental(rental);
	}

	@Override
	public Payment save(Payment payment) {
		return this.paymentDao.save(payment);
	}

}
